package com.yuezhix.elastic.config;


import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 加上 Configuration ，代表这是一个配置类
 */

@Configuration
public class ElasticSearchConfig {


    @Bean
    public TransportClient client() throws UnknownHostException {

        InetSocketTransportAddress node = new InetSocketTransportAddress(
            InetAddress.getByName("192.168.90.201"),
                9300
        );

        Settings settings = Settings.builder().put(
                "cluster.name","yuezhi"
        ).build();

        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(node);

        return client;

    }

}
